import { Checkbox, Select, Input } from 'antd';
import React from 'react';

const { Option } = Select;

interface ParamFormItemProps {
  value?: string;
  onChange?: (value: string) => void;
  options?: string;
}

// eslint-disable-next-line react/prefer-stateless-function
class ParamFormItem extends React.Component<ParamFormItemProps> {
  render() {
    return this.props.options ? (
      <Select
        placeholder="请选择"
        defaultValue={this.props.value}
        onChange={(value: string) => {
          if (this.props.onChange) {
            this.props.onChange(value);
          }
        }}
      >
        {this.props.options.split(',').map(item => (
          <Option key={item} value={item}>
            {item}
          </Option>
        ))}
      </Select>
    ) : (
      <Input
        defaultValue={this.props.value}
        onChange={value => {
          if (this.props.onChange) {
            this.props.onChange(value.target.value);
          }
        }}
      />
    );
  }
}

export default ParamFormItem;
